import easyquotation
import baostock as bs

from util.daylink import daylink
from scipy.signal import find_peaks
import numpy as np
import pandas as pd
from scipy import signal   #滤波等
import datetime

class WalkDataUtil():



    def   getWalkData(self,df_init):
        try:
            value_list = df_init.high.tolist()
            value_list = np.array(value_list)
            time_list = df_init.date.tolist()
            time_list = np.array(time_list)

            indices = find_peaks(value_list, height=None, threshold=None, distance=None,
                                 prominence=None, width=None, wlen=None, rel_height=None,
                                 plateau_size=None)
            stockdata = pd.DataFrame(columns=['val', 'ind', 'type', 'time', 'st'])
            # print(indices)

            val = value_list[indices[0]]
            ind = indices[0]
            for i in range(0, len(ind)):
                stockdata = stockdata.append({'val': val[i], 'ind': ind[i], 'type': 1, 'time': time_list[ind[i]], 'st': 1},
                                             ignore_index=True)

            value_list = df_init.low.tolist()
            value_list = np.array(value_list)
            # print(value_list)
            value_list = value_list * -1
            indices = find_peaks(value_list, height=None, threshold=None, distance=None,
                                 prominence=None, width=None, wlen=None, rel_height=None,
                                 plateau_size=None)
            # stockdata = pd.DataFrame(columns=['val', 'ind', 'type'])
            val = value_list[indices[0]]
            ind = indices[0]
            value_l = value_list * -1

            for i in range(0, len(ind)):
                stockdata = stockdata.append(
                    {'val': val[i] * -1, 'ind': ind[i], 'type': 2, 'time': time_list[ind[i]], 'st': 1}, ignore_index=True)
            stockdata = stockdata.sort_values(by=['ind'], ascending=False)
            return stockdata
        except Exception as e:
            return None